#include <stdio.h>
#include <getopt.h>

int main(int argc, char* argv[])
{
    int c = 0;
    int option_index = 0;
    int flag = -1;
    
    struct option long_options[] = {
        { "add",     required_argument, 0, 'a' },
        { "delete",  required_argument, 0, 'd' }, 
        { "clear",   no_argument,       0, 'c' },
        { "list",    optional_argument, 0, 'l' },
        { 0,         0,                 0,  0  }
    };

    while( 1 ) {
        int c = getopt_long(argc, argv, "a:d:cl::", long_options, &option_index);
        
        if( c == -1 )
            break;
        
        printf("c = %c, optopt = %c, optarg = %s\n", c, optopt, optarg);
    }

    if( optind < argc ) {
        printf("parameters:\n");
        
        while (optind < argc) {
            printf("%s\n", argv[optind++]);
        }
    }

    return 0;
}
